﻿CREATE PROCEDURE [dbo].[proc_ProjectExpenditure_GetList_Pay]
	(
		@Stext nvarchar(50),
		@CompanyId int,
		@StartIndex int,
		@EndIndex int
	)
AS
	;WITH list As
	(Select ROW_NUMBER() OVER (ORDER BY Id)AS Row,
		Id,
		PEId,
		ProjectName,
		Content,
		ApplyAmount,
		SubjectId,
		LaunchDate,
		IsNull(ManagerApprove,0) as ManagerApprove,
		ManagerApprovePerson,
		IsNull(ManagerApproveDate,'1900-01-01') as ManagerApproveDate,
		IsNull(FinanceApprove,0) as FinanceApprove,
		FinanceApprovePerson,
		IsNull(FinanceApproveDate,'1900-01-01') as FinanceApproveDate,
		Description,
		CompanyId,
		DepartmentId,
		(Select CompanyName From Company Where Id=ProjectExpenditure.CompanyId) As Company,
		(Select DName from Department Where Id=ProjectExpenditure.DepartmentId) As Department,
		(Select Title From Finance_Subject Where Id=ProjectExpenditure.SubjectId) As SubjectName,
		(Select E.EName From Employee E Where E.UserName=ProjectExpenditure.UserName) as UserName
		From ProjectExpenditure Where (@CompanyId=0 Or CompanyId=@CompanyId) and ManagerApprove=1 and FinanceApprove=1 and (@Stext is null Or ProjectName like '%'+@Stext+'%') 
	)
	Select * From list Where Row between @StartIndex and @EndIndex
	RETURN
